package cn.com.dev;

import cn.com.elite.Util;
import cn.com.kh.KHUtil;
import net.sf.json.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Dev7MoorCDR {
    private static final Log log = LogFactory.getLog(Dev7MoorCDR.class);

    public static void main(String[] args) throws Exception {

        String AccountID = "N00000003082";
        String APISecret = "fd7b96be-b6a1-48b7-a35d-e762008599b7";
        String APIURL = "https://yjwh.tycc100.com/v20180426/cdr/getCCCdr";

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String date = sdf.format(new Date());

        String bBase64 = AccountID + ":" + date;
        String Authorization = KHUtil.getbase64(bBase64);

        // 处理头文件
        Map<String, String> headerMap = new HashMap<String, String>();
        headerMap.put("Accept", "application/json");
        headerMap.put("Content-Type", "application/json");
        headerMap.put("Authorization", Authorization);

        // sig的值为 32位大写MD5加密 （帐号Id + 帐号APISecret +时间戳）
        String bSign = AccountID + APISecret + date;
        String sign = KHUtil.getMD5(bSign).toUpperCase();

        String postURL = APIURL + "/" + AccountID + "?sig=" + sign;
        JSONObject postBody = new JSONObject();
        postBody.put("beginTime", "2022-09-20 00:00:00");
        postBody.put("endTime", "2022-09-21 00:00:00");
        postBody.put("getAll", true);
        postBody.put("page", "1");
        postBody.put("pageSize", "1000");
        System.out.println("发送请求体：" + postBody.toString());

        // 调用API
        String postResult = Util.doHttpPostUseHead(postURL, postBody.toString(), "UTF-8", 120000, 0, headerMap);
        System.out.println("返回请求体：" + postResult);

    }
}
